﻿using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    public class OrderUnitEntityConfig : IEntityTypeConfiguration<Order>
    {
        public void Configure(EntityTypeBuilder<Order> builder)
        {
            builder.ToTable("T_Orders");
            builder.HasOne<Delivery>(o => o.Delivery)
                .WithOne(d => d.Order)
                .HasForeignKey<Delivery>(d => d.OrderId) //泛型T，指明外键所在类
                .OnDelete(DeleteBehavior.NoAction) // 解决下面错误,外键，级联关系，删除无动作
                //.IsRequired() 
                ;

            builder.Property(o => o.Name).IsRequired()
                .IsUnicode().HasMaxLength(100);
        }
    }
}
